const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Notifications = sequelize.define('Notifications', {
  id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    autoIncrement: true,
    comment: '通知ID',
  },
  userId: {
    type: DataTypes.BIGINT,
    allowNull: false,
    comment: '用户ID',
  },
  type: {
    type: DataTypes.ENUM,
    allowNull: false,
    comment: '通知类型',
  },
  title: {
    type: DataTypes.STRING(200),
    allowNull: false,
    comment: '通知标题',
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: false,
    comment: '通知内容',
  },
  status: {
    type: DataTypes.ENUM,
    defaultValue: pending,
    comment: '发送状态',
  },
  sentAt: {
    type: DataTypes.DATE,
    comment: '发送时间',
  },
  errorMessage: {
    type: DataTypes.TEXT,
    comment: '错误信息',
  },
  retryCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '重试次数',
  },
  deletedAt: {
    type: DataTypes.DATE,
    comment: '删除时间',
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: CURRENT_TIMESTAMP,
    comment: '创建时间',
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: CURRENT_TIMESTAMP,
    comment: '更新时间',
  }
}, {
  tableName: 'notifications',
  comment: '通知表',
  timestamps: true,
  paranoid: true,
  underscored: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  deletedAt: 'deleted_at'
});

module.exports = Notifications;
